<!--
Copyright 2012 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<!DOCTYPE html>

<style>
.scene {
  position: absolute;
  left: 50px;
}

.door {
  background-color: gray;
  border: 1px solid black;
  line-height: 200px;
  width: 100px;
}

.doorSpacer {
  width: 200px;
  -webkit-transform: rotateY(0deg);
  -webkit-transform-style: preserve-3d;
}

.doorContainer {
  -webkit-transform-style: preserve-3d;
  -webkit-perspective: 1000px;
  top: 50px;
  width: 200px;
  height: 200px;
  position: absolute;
  -webkit-perspective-origin: right center;
}

.right {
  left: 450px;
  visibility: hidden;
}

.picture {
  position: absolute;
  left: 150px;
  top: 70px;
  width: 100px;
  height: 75px;
  border: solid 1px black;
  -webkit-transform: rotate(0deg);
}

.dust {
  position: absolute;
  left: -25px;
  width: 150px;
  border-radius: 15px;
  height: 30px;
  top: 230px;
  background-color: #555;
  opacity: 0;
}

div#links {
  margin: 30px;
}

</style>

<div>TODO: Update me to use the new Player model !!!</div>

<div class="scene">
  <div class="doorContainer">
    <div class="doorSpacer" id="door">
      <div class="door">
      &nbsp;o
      </div>
    </div>
  </div>
  <div class="dust" id="dust"></div>

  <div class="picture" id="picture"></div>
</div>

<svg height="400px">
  <circle cx="100px" cy="100px" r="20px"/>
  <circle cx="200px" cy="120px" r="15px"/>
  <circle cx="130px" cy="315px" r="25px"/>
  <circle cx="220px" cy="300px" r="20px"/>
</svg>

<div id="links">
  <div>Use the links below to run the steps of the demo.</div>
  <a href="#" onclick="first()">first</a>
  <a href="#" onclick="second()">second</a>
  <a href="#" onclick="third()">third</a>
  <a href="#" onclick="fourth()">fourth</a>
  <a href="#" onclick="fifth()">fifth</a>
  <a href="#" onclick="sixth()">sixth</a>
  <a href="#" onclick="seventh()">seventh</a>
  <a href="#" onclick="eighth()">eighth</a>
</div>

<script src="../web-animations.js"></script>
<script>
"use strict";

// STEP 1

var a = undefined;

function first() {
  a = new Animation(document.querySelector(".doorSpacer"),
      [{'transform': 'rotateY(0deg)'}, {'transform': 'rotateY(100deg)'}], 2);
}

function second() {
  new Animation(document.querySelector("circle"), { cx: '400px' }, 3);
}

// STEP 2

function third() {
  a.specified.timingFunc = TimingFunction.createFromString('ease-in');
  document.timeline.play(a);
}

function fourth() {
  a.specified.timingFunc = TimingFunction.createFromString('cubic-beziel(0, 0.2,0.8, 1)');
  document.timeline.play(a);
}

// STEP 3

var group = undefined;
var pictureTilting = undefined;

function fifth() {
  var picture = document.querySelector(".picture");
  pictureTilting = new Animation(picture,
      [{'transform': 'rotate(0deg)'}, {'transform': 'rotate(-30deg)'}], 0.5);
  group = new SeqGroup([a, pictureTilting]);
}

function sixth() {
  var dust = document.querySelector(".dust");
  var dustPuff = new Animation(dust, [
    {opacity: "0"},
    {opacity: "0.4"},
    {opacity: "0"}
  ], 0.3);
  group.add(new ParGroup([ pictureTilting, dustPuff ]));
  document.timeline.play(group);
}

// STEP 4

function audioAnimFunction() {
  return {
    sample: function(timeFraction, currentIteration, target) {
      // TODO: fix this
      console.log(timeFraction);
    }
  };
}

function seventh() {
  var doorCreakAnim =
      new Animation(null, new audioAnimFunction("CREEEEEEAAAAKKK"), 2);
  var closeAnim = new ParGroup([ a, doorCreakAnim ]);
  closeAnim.specified.timingFunc = a.specified.timingFunc;
  a.specified.timingFunc = null;
  group.splice(0, 0, closeAnim);
  document.timeline.play(group);
}

// STEP 5

function eighth() {
  group.specified.playbackRate = 2;
  document.timeline.play(group);
}
</script>
<script src="../web-animations-visualization.js"></script>
